<?php
class Workflow_Condition_Variable implements Workflow_Condition
{
/**
     * The name of the variable the condition is applied to.
     *
     * @var string
     */
    protected $variableName;

    /**
     * The condition that is applied to the variable.
     *
     * @var Workflow_Condition
     */
    protected $condition;

    /**
     * Constructor.
     *
     * @param  string $variableName
     * @param  Workflow_Condition $condition
     */
    public function __construct( $variableName, Workflow_Condition $condition )
    {
        $this->variableName = $variableName;
        $this->condition    = $condition;
    }

    /**
     * Evaluates this condition.
     *
     * @param  mixed $value
     * @return boolean true when the condition holds, false otherwise.
     * @ignore
     */
    public function evaluate( $value )
    {
        if ( is_array( $value ) && isset( $value[$this->variableName] ) )
        {
            return $this->condition->evaluate( $value[$this->variableName] );
        }
        else
        {
            return false;
        }
    }   

    /**
     * Returns the name of the variable the condition is evaluated for.
     *
     * @return string
     * @ignore
     */
    public function getVariableName()
    {
        return $this->variableName;
    }

    /**
     * Returns the condition.
     *
     * @return Workflow_Condition
     * @ignore
     */
    public function getCondition()
    {
        return $this->condition;
    }
}
?>